import { ref } from 'vue'
import type PageModal from '@/components/page-modal/page-modal.vue'

type EditFnType = (data: any) => void

export function usePageModal(editCallback?: EditFnType) {
  const modalRef = ref<InstanceType<typeof PageModal>>()
  function handleNewClick() {
    modalRef.value?.setModalVisible()
  }
  function handleEditClick(data: any) {
    modalRef.value?.setModalVisible(false, data)
    if (editCallback) editCallback(data)
  }

  return {
    modalRef,
    handleNewClick,
    handleEditClick
  }
}
